package m.toolkit.console;

import m.framework.exception.SystemException;

/**
 * @author ming
 * @date 2014年2月22日下午9:52:27
 */
public class Command {

	enum Status {
		未知, 执行中, 成功, 失败, 中止, 取消
	}

	// 命令唯一标示
	private String commandId;
	// 命令所执行的脚本
	private String commandContent;
	// 当前状态,取消说明用户手动取消,中止是因为线程池满了
	private Status status;
	// 只有执行失败时这个才有只
	private Exception exception;
	// 执行结果,因为执行时异步的,客户端不能每次都获取全部结果,获取时得传一个已读位置
	private OutputHolder outputHolder;
	// 执行结果以多少秒进行分割
	private Integer outSpilt;
	// 最多保留多少份的执行结果
	private Integer outSize;
	// 结果的字符集
	private String charsetName;
	// 命令执行开始时间
	private Long beginTime;
	// 执行结束时间
	private Long endTime;
	// 当前要输出到页面的out
	private String curentOutput;
	// 最后更新时间
	private Long lastUpdatetTime;

	public String getCommandId() {
		return commandId;
	}

	public void setCommandId(String commandId) {
		this.commandId = commandId;
	}

	public String getCommandContent() {
		return commandContent;
	}

	public void setCommandContent(String commandContent) {
		this.commandContent = commandContent;
	}

	public Status getStatus() {
		return status;
	}

	public Exception getException() {
		return exception;
	}

	public void setException(Exception exception) {
		this.exception = exception;
	}

	public Integer getOutSpilt() {
		return outSpilt;
	}

	public void setOutSpilt(Integer outSpilt) {
		this.outSpilt = outSpilt;
	}

	public Integer getOutSize() {
		return outSize;
	}

	public void setOutSize(Integer outSize) {
		this.outSize = outSize;
	}

	public String getCharsetName() {
		return charsetName;
	}

	public void setCharsetName(String charsetName) {
		this.charsetName = charsetName;
	}

	public OutputHolder getOutputHolder() {
		return outputHolder;
	}

	public void setOutputHolder(OutputHolder outputHolder) {
		this.outputHolder = outputHolder;
	}

	public Long getBeginTime() {
		return beginTime;
	}

	public void setBeginTime(Long beginTime) {
		this.beginTime = beginTime;
	}

	public Long getEndTime() {
		return endTime;
	}

	public void setEndTime(Long endTime) {
		this.endTime = endTime;
	}

	// 更新命令执行状态
	synchronized public void updateStatus(Status from, Status to) {
		if (from != null && this.getStatus() != from) {
			throw new SystemException("数据状态已经改变为:" + this.getStatus());
		}
		this.status = to;
	}

	public String getCurentOutput() {
		return curentOutput;
	}

	public void setCurentOutput(String curentOutput) {
		this.curentOutput = curentOutput;
	}

	public Long getLastUpdatetTime() {
		return lastUpdatetTime;
	}

	public void setLastUpdatetTime(Long lastUpdatetTime) {
		this.lastUpdatetTime = lastUpdatetTime;
	}

}
